//
//  BK_SPS_Detail_Cell.m
//  bestkeep
//
//  Created by TOPTEAM on 2017/4/6.
//  Copyright © 2017年 utouu. All rights reserved.
//

#import "BK_SPS_Detail_Cell.h"
#import <Masonry.h>
#import "BK_OD_Color.h"

#import "BKUserStatusInfo.h"



@interface BK_SPS_Detail_Cell ()

@property (nonatomic,strong) UIView * view_back;
@property (nonatomic,strong) UILabel* lab_title;       //实付款
@property (nonatomic,strong) UILabel* lab_Money;         //
@property (nonatomic,strong) UILabel* lab_detail;       //

@end
@implementation BK_SPS_Detail_Cell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        self.backgroundColor = [UIColor whiteColor];
        [self initView];
    }
    return self;
}

- (void)initView{
    /**
     * 背景View---白色
     */
    _view_back =[[UIView alloc]init];
    _view_back.backgroundColor=[UIColor whiteColor];
    [self addSubview:_view_back];
    [_view_back mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(0);
        make.left.equalTo(self.mas_left).offset(0);
        make.width.mas_equalTo(@(ScreenWidth));
        make.bottom.equalTo(self.mas_bottom);
    }];
    
    /**
     *  实付金额
     */
    _lab_title= [UILabel new];
    _lab_title.textColor = kOrderBlack3;
    _lab_title.font = [UIFont systemFontOfSize:15];
    _lab_title.numberOfLines=1;
    _lab_title.text = @"实付金额";
    _lab_title.textAlignment=NSTextAlignmentLeft;
    _lab_title.backgroundColor = [UIColor clearColor];
    [_view_back addSubview:_lab_title];
    [_lab_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_view_back.mas_top).offset(10);
        make.left.mas_equalTo(_view_back.mas_left).offset(ApplicationBackGauge);
        make.right.mas_equalTo(self.mas_right).offset(-30);
    }];
    
    
    
    _lab_Money= [UILabel new];
    _lab_Money.textColor = kOrderBlack3;
    _lab_Money.font = [UIFont systemFontOfSize:40];
    _lab_Money.numberOfLines=1;
    _lab_Money.textAlignment=NSTextAlignmentCenter;
    _lab_Money.text = @"加载中....";
    _lab_Money.backgroundColor = [UIColor clearColor];
    [_view_back addSubview:_lab_Money];
    [_lab_Money mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.mas_equalTo(_view_back.mas_top).offset(96.5/2.0);
        make.left.mas_equalTo(_view_back.mas_left).offset(0);
        make.right.mas_equalTo(_view_back.mas_right).offset(0);
        make.height.mas_equalTo(112/2.0);
        
    }];
    
    
    
    _lab_detail= [UILabel new];
    _lab_detail.textColor = kOrderMediumGrey2;
    _lab_detail.font = [UIFont boldSystemFontOfSize:14];
    _lab_detail.numberOfLines=1;
//    _lab_detail.text = @"本次消费节省 ¥5.00";
    _lab_detail.textAlignment=NSTextAlignmentCenter;
    _lab_detail.backgroundColor = [UIColor clearColor];
    [_view_back addSubview:_lab_detail];
    [_lab_detail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_lab_Money.mas_bottom).offset(5);
        make.right.mas_equalTo(_view_back.mas_right).offset(-ApplicationBackGauge);
        make.left.mas_equalTo(_view_back.mas_left).offset(ApplicationBackGauge);
    }];
    
    
    
    
    
}

-(void)relayOut_UI:(BK_SP_OD_Model*)model{
    
    
    //        [---POST----Result----200--]:{"code":"","data":{"order_no":"20170410112346233229","store_address":"陕西省-西安市碑林区店","pay_amount":45,"pay_way":10,"create_time":"2017-04-10 11:23:45","pay_status":1,"discount_amount":0},"success":true,"msg":""}     --request.URL-->http://api.test.bestkeep.cn/store/getOrder?orderNo=20170410112346233229
    
        
        
    NSString * str_Money=[NSString stringWithFormat:@"%@",model.pay_amount];
    _lab_Money.text = [NSString stringWithFormat:@"¥%.2f",[str_Money floatValue]];

    BKUserStatusInfo * userStatusInfo =[BKUserStatusInfo currentUser];
    if ([userStatusInfo.vipFlag integerValue]==1) {
        /*
         * 如果是VIP
         */
       
        NSString *discount_amount=[NSString stringWithFormat:@"%@",model.discount_amount];
        if ([discount_amount floatValue]>0) {
            NSString *str_all =[NSString stringWithFormat:@"本次消费共节省 ¥%.2f",[discount_amount floatValue]];
            NSString *str_left=@"本次消费共节省 ";
            NSMutableAttributedString *attri =  [[NSMutableAttributedString alloc] initWithString:str_all];
            
            
            // 修改富文本中的不同文字的样式
            [attri addAttribute:NSForegroundColorAttributeName value:kOrderMediumGrey2 range:NSMakeRange(0, str_left.length)];
            [attri addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(0, str_left.length)];
            
            // 设置数字为红色
            [attri addAttribute:NSForegroundColorAttributeName value:kOrderPriceRed range:NSMakeRange(str_left.length, str_all.length-str_left.length)];
            [attri addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(str_left.length, str_all.length-str_left.length)];
            
            _lab_detail.attributedText=attri;
        }else{
            _lab_detail.hidden=YES;
        }
        
    }else{
        /*
         * 不是VIP
         */
     
        
        
    }
    
    
    
    
}




- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
+(CGFloat)computeHeight:(id)data{
    return 333/2.0;
}
@end
